Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
76 / 76
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ServiceProvider
100.00% covered (success)
100.00%
76 / 76
100.00% covered (success)
100.00%
6 / 6
37
100.00% covered (success)
100.00%
1 / 1
 boot
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 about
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
1 / 1
24
 userPrimaryKeyType
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 userPrimaryKeyTypeParse
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
1 / 1
4
 register
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 version
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4/**
5 * Playground
6 */
7namespace Playground;
8
9use Illuminate\Foundation\Console\AboutCommand;
10use Illuminate\Foundation\Support\Providers\AuthServiceProvider;
11
12/**
13 * \Playground\ServiceProvider
14 */
15class ServiceProvider extends AuthServiceProvider
16{
17    protected string $package = 'playground';
18
19    public const VERSION = '73.0.0';
20
21    public function boot(): void
22    {
23        /**
24         * @var array<string, mixed> $config
25         */
26        $config = config($this->package);
27
28        if ($this->app->runningInConsole()) {
29            // Publish configuration
30            $this->publishes([
31                sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package) => config_path(sprintf('%1$s.php', $this->package)),
32            ], 'playground-config');
33        }
34
35        if (! empty($config['about'])) {
36            $this->about($config);
37        }
38    }
39
40    /**
41     * @param array<string, mixed> $config
42     */
43    public function about(array $config): void
44    {
45        $packages = ! empty($config['packages']) && is_array($config['packages']) ? $config['packages'] : [];
46
47        $version = $this->version();
48
49        /**
50         * @var class-string $auth_providers_users_model
51         */
52        $auth_providers_users_model = config('auth.providers.users.model');
53
54        AboutCommand::add('Playground', fn () => [
55            '<fg=cyan;options=bold>User</> [auth.providers.users.model]' => sprintf('[%s]', is_string($auth_providers_users_model) ? $auth_providers_users_model : ''),
56            '<fg=cyan;options=bold>User Primary</>' => $this->userPrimaryKeyType($auth_providers_users_model),
57
58            '<fg=cyan;options=bold>User</> Illuminate\Database\Eloquent\Factories\HasFactory' => $this->userHasFactory ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
59            '<fg=cyan;options=bold>User</> Illuminate\Database\Eloquent\Model' => $this->userIsEloquentModel ? '<fg=green;options=bold>EXTENDED</>' : '<fg=yellow;options=bold>NOT EXTENDED</>',
60            '<fg=cyan;options=bold>User</> Illuminate\Database\Eloquent\Concerns\HasUuids' => $this->userHasEloquentUuids ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
61            '<fg=cyan;options=bold>User</> Illuminate\Notifications\Notifiable' => $this->userHasNotifiable ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
62            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\MustVerifyEmail' => $this->userHasMustVerifyEmail ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
63
64            '<fg=cyan;options=bold>User</> Illuminate\Auth\Passwords\CanResetPassword' => $this->userCanResetPasswordConcern ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
65            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\CanResetPassword' => $this->userCanResetPasswordContract ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
66
67            '<fg=cyan;options=bold>User</> Illuminate\Foundation\Auth\Access\Authorizable' => $this->userHasAuthorizableConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
68            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\Access\Authorizable' => $this->userHasAuthorizableContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
69
70            '<fg=cyan;options=bold>User</> Illuminate\Auth\Authenticatable' => $this->userHasAuthenticatableConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
71            '<fg=cyan;options=bold>User</> Illuminate\Contracts\Auth\Authenticatable' => $this->userHasAuthenticatableContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
72
73            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Abilities' => $this->userPlaygroundAbilitiesConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
74            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Abilities' => $this->userHasPlaygroundAbilitiesContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
75
76            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Admin' => $this->userPlaygroundAdminConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
77            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Admin' => $this->userHasPlaygroundAdminContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
78
79            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Privileges' => $this->userPlaygroundPrivilegesConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
80            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Privileges' => $this->userHasPlaygroundPrivilegesContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
81
82            '<fg=cyan;options=bold>User</> Playground\Models\Concerns\Role' => $this->userPlaygroundRoleConcerns ? '<fg=green;options=bold>USED</>' : '<fg=yellow;options=bold>NOT USED</>',
83            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\Role' => $this->userHasPlaygroundRoleContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
84
85            '<fg=cyan;options=bold>User</> Playground\Models\Contracts\WithMatrix' => $this->userHasPlaygroundMatrixContracts ? '<fg=green;options=bold>IMPLEMENTED</>' : '<fg=yellow;options=bold>NOT IMPLEMENTED</>',
86
87            'Packages' => implode(', ', $packages),
88            'Package' => $this->package,
89            'Version' => $version,
90        ]);
91    }
92
93    /**
94     * @param ?class-string $auth_providers_users_model
95     */
96    public function userPrimaryKeyType(string $auth_providers_users_model = null): string
97    {
98        try {
99            if (! $auth_providers_users_model || ! class_exists($auth_providers_users_model)) {
100                return '<fg=yellow;options=bold>invalid</>';
101            }
102
103            return $this->userPrimaryKeyTypeParse($auth_providers_users_model);
104        } catch (\Throwable $th) {
105            \Log::debug($th->__toString());
106
107            return '<fg=red;options=bold>error</>';
108        }
109    }
110
111    protected bool $userHasFactory;
112
113    protected bool $userCanResetPasswordConcern;
114
115    protected bool $userCanResetPasswordContract;
116
117    protected bool $userHasAuthorizableConcerns;
118
119    protected bool $userHasAuthorizableContracts;
120
121    protected bool $userIsEloquentModel;
122
123    protected bool $userHasEloquentUuids;
124
125    protected bool $userHasNotifiable;
126
127    protected bool $userHasAuthenticatableConcerns;
128
129    protected bool $userHasAuthenticatableContracts;
130
131    protected bool $userHasMustVerifyEmail;
132
133    protected bool $userPlaygroundAbilitiesConcerns;
134
135    protected bool $userHasPlaygroundAbilitiesContracts;
136
137    protected bool $userPlaygroundAdminConcerns;
138
139    protected bool $userHasPlaygroundAdminContracts;
140
141    protected bool $userPlaygroundPrivilegesConcerns;
142
143    protected bool $userHasPlaygroundPrivilegesContracts;
144
145    protected bool $userPlaygroundRoleConcerns;
146
147    protected bool $userHasPlaygroundRoleContracts;
148
149    protected bool $userHasPlaygroundMatrixContracts;
150
151    /**
152     * @param class-string $auth_providers_users_model
153     */
154    private function userPrimaryKeyTypeParse(string $auth_providers_users_model): string
155    {
156        $model_info = '';
157        /**
158         * @var \Illuminate\Contracts\Auth\Authenticatable
159         */
160        $user = new $auth_providers_users_model;
161
162        $this->userHasFactory = in_array(\Illuminate\Database\Eloquent\Factories\HasFactory::class, class_uses_recursive($user));
163
164        $this->userCanResetPasswordConcern = in_array(\Illuminate\Auth\Passwords\CanResetPassword::class, class_uses_recursive($user));
165        $this->userCanResetPasswordContract = $user instanceof \Illuminate\Contracts\Auth\CanResetPassword;
166
167        $this->userHasAuthorizableConcerns = in_array(\Illuminate\Foundation\Auth\Access\Authorizable::class, class_uses_recursive($user));
168        $this->userHasAuthorizableContracts = $user instanceof \Illuminate\Contracts\Auth\Access\Authorizable;
169
170        $this->userIsEloquentModel = $user instanceof \Illuminate\Database\Eloquent\Model;
171
172        $this->userHasEloquentUuids = in_array(\Illuminate\Database\Eloquent\Concerns\HasUuids::class, class_uses_recursive($user));
173        $this->userHasNotifiable = in_array(\Illuminate\Notifications\Notifiable::class, class_uses_recursive($user));
174
175        $this->userHasAuthenticatableConcerns = in_array(\Illuminate\Auth\Authenticatable::class, class_uses_recursive($user));
176        $this->userHasAuthenticatableContracts = $user instanceof \Illuminate\Contracts\Auth\Authenticatable;
177
178        $this->userHasMustVerifyEmail = $user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail;
179
180        $this->userPlaygroundAbilitiesConcerns = in_array(Models\Concerns\Abilities::class, class_uses_recursive($user));
181        $this->userHasPlaygroundAbilitiesContracts = $user instanceof Models\Contracts\Abilities;
182
183        $this->userPlaygroundAdminConcerns = in_array(Models\Concerns\Admin::class, class_uses_recursive($user));
184        $this->userHasPlaygroundAdminContracts = $user instanceof Models\Contracts\Admin;
185
186        $this->userPlaygroundPrivilegesConcerns = in_array(Models\Concerns\Privileges::class, class_uses_recursive($user));
187        $this->userHasPlaygroundPrivilegesContracts = $user instanceof Models\Contracts\Privileges;
188
189        $this->userPlaygroundRoleConcerns = in_array(Models\Concerns\Role::class, class_uses_recursive($user));
190        $this->userHasPlaygroundRoleContracts = $user instanceof Models\Contracts\Role;
191
192        $this->userHasPlaygroundMatrixContracts = $user instanceof Models\Contracts\WithMatrix;
193
194        if (in_array(\Illuminate\Database\Eloquent\Concerns\HasUuids::class, class_uses_recursive($user))
195            && ! $user->getIncrementing()
196        ) {
197            $model_info = '<fg=green;options=bold>UUID</>';
198        } elseif ($user->getIncrementing()) {
199            $model_info = '<fg=green;options=bold>increments</>';
200        }
201
202        return $model_info;
203    }
204
205    public function register(): void
206    {
207        $this->mergeConfigFrom(
208            sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package),
209            $this->package
210        );
211    }
212
213    public function version(): string
214    {
215        return static::VERSION;
216    }
217}